import http from '../utils/request.js'
import qs from 'qs';

// 用户登陆API
export function userLoginApi(data) {
    return http({
        url: '/account/login',
        method: 'post',
        data: qs.stringify(data),
    })
}

// 获取用户列表API
export function userListApi(data) {
    return http({
        url: '/user/user',
        method: 'get',
        params: data ? data : ''
    })
}

// 修改用户状态
export function editStateApi(data) {
    if (data.keyword != 'level') data.value = data.value ? '1' : '0'
    return http({
        url: `user/user/${data.id}/status/${data.keyword}/${data.value}`,
        method: 'put',
    })
}

// 删除用户
export function userDeleteApi(id) {
    return http({
        url: `user/user/${id}`,
        method: 'delete',
    })
}

// 模糊查询
export function userListLikeApi(option) {
    return http({
        url: `user/like/${option.class}/${option.keyword}`,
        method: 'GET',
        params: option.pagination ? option.pagination : ''
    })
}

// 添加用户
export function userAddApi(data) {
    return http({
        url: `user/user`,
        method: 'post',
        data: qs.stringify(data),
    })
}

// 根据id查询用户
export function userByIdApi(id) {
    return http({
        url: `user/user/${id}`,
        method: 'get',
    })
}

// 修改用户
export function UserEditApi(id, data) {
    console.log(data);
    return http({
        url: `user/user/${id}`,
        method: 'put',
        data: qs.stringify(data),
    })
}